package com.lingying.caiwudailikehudaun.mapper.wuPinJiaoJIe;

import com.lingying.caiwudailikehudaun.domain.wuPinJiaoJie.WuPinJiaoJieBean;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
@Mapper
public interface WuPinJiaoJieMapper {

    /**
     * 查询物品物品汇总的提交人信息
     * 桑满
     * @param suoShuDaiLiShangId
     * @return
     */
    @Select("SELECT DISTINCT  tianXieUserId,tianXieUserName FROM wuPinJiaoJie WHERE suoShuDaiLiShangId = #{suoShuDaiLiShangId} AND tianXieUserId is NOT NULL")
    List<Map<Integer,String>> selectTianXieRen(Integer suoShuDaiLiShangId);

    /**
     * 查询物品交接汇总的所有数据
     * 祁青林 20210430
     * @param pages
     * @param limit
     * @return
     */
    @Select({"<script>" +
            "SELECT\n" +
            "\tw.wuPinJiaoJieId,\n" +
            "\tw.companyName,\n" +
            "\tw.jiaoJieType,\n" +
            "\tw.jiaoJieShiJian,\n" +
            "\tw.sendUser,\n" +
            "\tw.acceptUser,\n" +
            "\tw.shenPiZhuangTai,\n" +
            "\tw.jiaoJieFangShi,\n" +
            "\tw.jiaoJieWuPin,\n" +
            "\tw.tianXieUserId,\n" +
            "\tw.tianXieUserName,\n" +
            "\tw.createTime,\n" +
            "\tw.shenPiTime \n" +
            "FROM\n" +
            "\twuPinJiaoJie w \n" +
            "WHERE\n" +
            "\tw.daiLiShangCid = #{daiLiShangCid} \n" +
            "\tAND w.xianShiZhuangTai = 1 and w.jiaoJieType = #{jiaoJieType} " +
            "<if test=\" jiaoJieFangShi != null and jiaoJieFangShi != ''\">" +
            " and w.jiaoJieFangShi = #{jiaoJieFangShi} " +
            "</if>" +
            "<if test=\" sendUser != null and sendUser != ''\">" +
            " and w.sendUser like concat('%', #{sendUser} ,'%')" +
            "</if>" +
            "<if test=\" acceptUser != null and acceptUser != ''\">" +
            " and w.acceptUser like concat('%', #{acceptUser} ,'%')" +
            "</if>" +
            "<if test=\" tianXieUserId != null and tianXieUserId != ''\">" +
            " and w.tianXieUserId = #{tianXieUserId}" +
            "</if>" +
            "<if test=\" jiaoJieShiJianBegin != null and jiaoJieShiJianBegin != ''\">" +
            " and w.jiaoJieShiJian &gt;= #{jiaoJieShiJianBegin}" +
            "</if>" +
            "<if test=\" jiaoJieShiJianEnd != null and jiaoJieShiJianEnd != ''\">" +
            " and w.jiaoJieShiJian &lt;= #{jiaoJieShiJianEnd}" +
            "</if>" +
            "<if test=\" jiaoJieShiJianBegin != null and jiaoJieShiJianBegin != '' and jiaoJieShiJianEnd != null and jiaoJieShiJianEnd != ''\">" +
            " and #{jiaoJieShiJianBegin} &lt;= w.jiaoJieShiJian &lt;= #{jiaoJieShiJianEnd}" +
            "</if>" +
            " ORDER BY w.createTime DESC LIMIT #{pages},#{limit}" +
            "</script>"})
    List<WuPinJiaoJieBean> selectWuPinJiaoJie(Integer daiLiShangCid, String jiaoJieFangShi,
                                              String jiaoJieType, String sendUser, String acceptUser,
                                              Integer tianXieUserId, String jiaoJieShiJianBegin, String jiaoJieShiJianEnd, Integer pages, Integer limit);
    //总个数
    @Select({"<script>" +
            "SELECT\n" +
            "\tCOUNT(*)\n" +
            "FROM\n" +
            "\twuPinJiaoJie w \n" +
            "WHERE\n" +
            "\tw.daiLiShangCid = #{daiLiShangCid} \n" +
            "\tAND w.xianShiZhuangTai = 1 and w.jiaoJieType = #{jiaoJieType} " +
            "<if test=\" jiaoJieFangShi != null and jiaoJieFangShi != ''\">" +
            " and w.jiaoJieFangShi = #{jiaoJieFangShi} " +
            "</if>" +
            "<if test=\" sendUser != null and sendUser != ''\">" +
            " and w.sendUser like concat('%', #{sendUser} ,'%')" +
            "</if>" +
            "<if test=\" acceptUser != null and acceptUser != ''\">" +
            " and w.acceptUser like concat('%', #{acceptUser} ,'%')" +
            "</if>" +
            "<if test=\" tianXieUserId != null and tianXieUserId != ''\">" +
            " and w.tianXieUserId = #{tianXieUserId}" +
            "</if>" +
            "<if test=\" jiaoJieShiJianBegin != null and jiaoJieShiJianBegin != ''\">" +
            " and w.jiaoJieShiJian &gt;= #{jiaoJieShiJianBegin}" +
            "</if>" +
            "<if test=\" jiaoJieShiJianEnd != null and jiaoJieShiJianEnd != ''\">" +
            " and w.jiaoJieShiJian &lt;= #{jiaoJieShiJianEnd}" +
            "</if>" +
            "<if test=\" jiaoJieShiJianBegin != null and jiaoJieShiJianBegin != '' and jiaoJieShiJianEnd != null and jiaoJieShiJianEnd != ''\">" +
            " and #{jiaoJieShiJianBegin} &lt;= w.jiaoJieShiJian &lt;= #{jiaoJieShiJianEnd}" +
            "</if>" +
            "</script>"})
    Integer selectWuPinJiaoJieCount(Integer daiLiShangCid,String jiaoJieFangShi,
                                    String jiaoJieType,String sendUser,String acceptUser,
                                    Integer tianXieUserId,String jiaoJieShiJianBegin,String jiaoJieShiJianEnd);

    /**
     * 根据物品交接ID找到当前物品交接审批状态
     * @param shenPiId
     * @return
     */
    @Select("SELECT shenPiZhuangTai from wuPinJiaoJie WHERE wuPinJiaoJieId=#{shenPiId}")
    Integer selectShenPiZhuangTai(Integer shenPiId);

    /**
     * 根据物品交接ID查询物品交接表中的其他数据
     * @param shenPiId
     * @return
     */
    @Select("select * from wuPinJiaoJie where wuPinJiaoJieId=#{shenPiId}")
//    List<jiaoJieShenPiDTO> selectaddWuPinTable(Integer wupinjiaojieid);
    Map<String,Object> selectWuPinTable(Integer shenPiId);

    /**
     * 查看当前物品交接的审批人及其审批状态
     * @param shenPiId
     * @return
     */
    @Select("select DISTINCT shenPiZhuangTai,shenPiRenName from shenPiRen where jinYong=0 and shenPiId=#{shenPiId} and shenPiTypeId = #{shenPiType} ")
    List<Map<Integer,String>> selectShenPiXinXi(Integer shenPiId,Integer shenPiType);

    /**
     * 查看当前物品交接的抄送人
     * @param shenPiId
     * @return
     */
    @Select("select DISTINCT chaoSongRenName from chaoSongRen where jinYong=0 and shenPiId=#{shenPiId} and shenPiTypeId = #{shenPiType}")
    List<String> selectChaoSongRen(Integer shenPiId,Integer shenPiType);

    /**
     * 查询提交人名字
     * @param wupinjiaojieid
     * @return
     */
    @Select("SELECT tianXieUserName, jiaoJieShiJian from wuPinJiaoJie WHERE wuPinJiaoJieId=#{wupinjiaojieid}")
    WuPinJiaoJieBean selectTiJiaoRen(Integer wupinjiaojieid);

    /**
     * 查询审批记录
     * @param shenPiId
     * @return
     */
    @Select("SELECT shenPiZhuangTai,shenPiRenName,shenPiRenId,updateTime FROM shenPiRen WHERE shenPiTypeId = #{shenPiType} and shenPiId=#{shenPiId} ORDER BY updateTime ")
    List<Map<String,Object>> selectshenpiyijian( Integer shenPiId ,Integer shenPiType);

    /**
     * 根据物品交接ID和提交人ID查询到所填写的拒绝意见
     * @param shenPiId
     * @return
     */
    @Select(" SELECT refuseYiJian from shenPiYiJian WHERE shenPiId=#{shenPiId} AND shenPiTypeId = #{shenPiType} AND checkRenId=#{shenPinRenId} and shenPiZhuangTai !=66")
    String selectjujuedata(Integer shenPiId,Integer shenPinRenId ,Integer shenPiType);

    /**
     * 根据物品交接ID找当文件储存路径
     * @param wupinjiaojieid
     * @return
     */
    @Select("select uploadFileId,filePath,weiXinPath,fileName,yinPinPath from uploadFile WHERE  wuPinJiaoJieId = #{wupinjiaojieid}")
    List<Map> selectfilepath(Integer wupinjiaojieid);
}
